package com.clean.scanlibrary.dialog

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.graphics.BitmapFactory
import android.view.LayoutInflater
import com.bumptech.glide.Glide
import oa.lla.cca.R
import oa.lla.cca.databinding.ActivityPicshowLayoutBinding

class BlackAndWhiteDialog:Dialog {
    private var mContext:Context? = null

    private var dataBind:ActivityPicshowLayoutBinding? = null
    constructor(context: Context) : super(context){
        mContext = context
        initView()
    }
    constructor(context: Context, themeResId: Int) : super(context, themeResId){
        mContext = context
        initView()
    }
    constructor(
        context: Context,
        cancelable: Boolean,
        cancelListener: DialogInterface.OnCancelListener?
    ) : super(context, cancelable, cancelListener){
        mContext = context
        initView()
    }

    private fun initView() {
        val inflate = LayoutInflater.from(context).inflate(R.layout.activity_picshow_layout, null)
        dataBind = ActivityPicshowLayoutBinding.bind(inflate)

        setContentView(dataBind!!.root)
    }

    fun showPicView(oldPic:String,newPic:String?){
        try {
            val input: ByteArray = android.util.Base64.decode(newPic, android.util.Base64.DEFAULT)
            val bitmap = BitmapFactory.decodeByteArray(input, 0, input!!.size)
            Glide.with(context).load(oldPic).into(dataBind!!.originalPic)
            Glide.with(context).load(bitmap).into(dataBind!!.nowPic)
        } catch (e : Exception){
            e.printStackTrace()
        }

    }


}